package cn.readjava.service.impl;

import cn.readjava.bean.User;
import cn.readjava.dao.UserDao;
import cn.readjava.service.UserService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@CacheConfig(cacheNames = "user")
public class UserServiceImpl implements UserService {

    @Resource
    private UserDao userDao;

    @Override
//    @CacheEvict(allEntries = true)
    public User save(User user) {
        return userDao.save(user);
    }

    @Override
    @Cacheable(key = "'user ' + #p0")
    public User getOne(Long userId) {
        return userDao.getOne(userId);
    }

    @Override
    public void deleteById(Long id) {
        userDao.deleteById(id);
    }

    @Override
    public User findByUserEmail(String userEmail) {
        return userDao.findByUserEmail(userEmail);
    }

    @Override
    public User findByUserName(String userName) {
        return userDao.findByUserName(userName);
    }
}
